package com.lewis.xuanke.controller;


import com.lewis.xuanke.entity.ComResult;
import com.lewis.xuanke.entity.Dict;
import com.lewis.xuanke.mapper.DictMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

//字典
@RestController
@RequestMapping(value = "/dict")
public class DistController {
    @Autowired
    DictMapper dictMapper;

    //查询字典
    @RequestMapping(value = "/getDisByKey", method = RequestMethod.POST)
    public ComResult<List<Dict>> getDisByKey(String key) {

        List<Dict> tJds = dictMapper.selectAll();
        List<Dict> marks = new ArrayList<>();
        ComResult<List<Dict>> result = new ComResult<>();
        result.setMsg("success");
        for (int i = 0; i < tJds.size(); i++) {
            Dict mark = tJds.get(i);
            if (mark.getKey().equals(key)) {
                marks.add(mark);
            }
        }
        result.setCode(0);
        result.setData(marks);
        return result;
    }


}
